local DataMgr = class("DataMgr");
local LoginData = require(SCRIPTS_DIR .. ".datas.LoginData");
local BattleData = require(SCRIPTS_DIR .. ".datas.BattleData");
local PlayerData = require(SCRIPTS_DIR .. ".datas.PlayerData");

function DataMgr:ctor()
    self.loginData = LoginData.new();
    self.battleData = BattleData.new();
    self.playerData = PlayerData.new();
    self:setSocketEvent()
    self:registerProtoMsg();
end

function DataMgr:getLoginData()
    return self.loginData;
end

function DataMgr:getBattleData()
    return self.battleData;
end

function DataMgr:getPlayerData()
    return self.playerData;
end

function DataMgr:setSocketEvent()
    -- body
    mgrs.event:addEventListener(enums.Event.SocketOpen,function(d)
        if d.data == enums.Socket.Login then
            mgrs.log:printDebug("SocketOpen Login")
        elseif d.data == enums.Socket.Game then
            mgrs.log:printDebug("SocketOpen Game")
            self.loginData:LoginGame()
        end
    end)

    mgrs.event:addEventListener(enums.Event.SocketClosed,function(d)
        if d.data == enums.Socket.Login then
            mgrs.log:printDebug("SocketClosed Login")
        elseif d.data == enums.Socket.Game then
            mgrs.log:printDebug("SocketClosed Game")
            mgrs.wnd:closeWnd(enums.Wnd.Battle)
        end
    end)
end

function DataMgr:registerProtoMsg()
    
    mgrs.proto:registerMsg(enums.NetCmd.CMD_L2C_LOGIN,handler(self.loginData,self.loginData.parseLogin)); --2001
    mgrs.proto:registerMsg(enums.NetCmd.CMD_L2C_REGISTER,handler(self.loginData,self.loginData.parseRegister)); --2002
    --mgrs.proto:registerMsg(enums.NetCmd.CMD_L2C_GATEINFO,handler(self.loginData,self.loginData.parseGateInfo)); --2004
    --mgrs.proto:registerMsg(enums.NetCmd.CMD_GATE2C_KICK_USER,handler(self.loginData,self.loginData.parseKickUser)); --4002
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_USER_LOGIN,handler(self.loginData,self.loginData.parseUserLogin)); --6001
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_BASEINFO,handler(self.loginData,self.loginData.parseBaseInfo)); --6002
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_PROP,handler(self.loginData,self.loginData.parseProp)); --6003
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_PROPERTY,handler(self.loginData,self.loginData.parseProperty)); --6004
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_CREATE_TABLE,handler(self.loginData,self.loginData.parseCreateTable)) -- 6005
    mgrs.proto:registerMsg(enums.NetCmd.CMD_CT2C_ENTER_TABLE,handler(self.loginData,self.loginData.parseGameServerInfo)) -- 6006
    mgrs.proto:registerMsg(enums.NetCmd.CMD_GAME2C_LOGIN,handler(self.loginData,self.loginData.parseLoginGame)) -- 8001
    mgrs.proto:registerMsg(enums.NetCmd.CMD_GAME2C_SELF_ENTER,handler(self.loginData,self.loginData.parseSelfEnterGame)) -- 8002
    mgrs.proto:registerMsg(enums.NetCmd.CMD_GAME2C_JOIN,handler(self.loginData,self.loginData.parseJoinTable)) -- 8003
    mgrs.proto:registerMsg(enums.NetCmd.CMD_GAME2C_OTHER_ENTER,handler(self.loginData,self.loginData.parseOtherEnterGame)) -- 8004
    mgrs.proto:registerMsg(4004,handler(self.loginData,self.loginData.initHour))
    mgrs.proto:registerMsg(2003,handler(self.loginData,self.loginData.parseHallInfo))
    mgrs.proto:registerMsg(2004,handler(self.loginData,self.loginData.parseServerTime))
    mgrs.proto:registerMsg(2005,handler(self.loginData,self.loginData.parseKickUser))
    mgrs.proto:registerMsg(2006,handler(self.loginData,self.loginData.parseCreateOrder))
    mgrs.proto:registerMsg(2007,handler(self.loginData,self.loginData.parseGetMail))
    mgrs.proto:registerMsg(6007,handler(self.loginData,self.loginData.parseCharge))
    mgrs.proto:registerMsg(6008,handler(self.loginData,self.loginData.parsePropertyUpdate))
    mgrs.proto:registerMsg(6009,handler(self.loginData,self.loginData.parseBindInviteCode))
    mgrs.proto:registerMsg(6010,handler(self.loginData,self.loginData.parseMailAttach))
    mgrs.proto:registerMsg(6012,handler(self.loginData,self.loginData.parseGetNewBie))
    mgrs.proto:registerMsg(6013,handler(self.loginData,self.loginData.parseSignInfo))
    mgrs.proto:registerMsg(6014,handler(self.loginData,self.loginData.parseSignReward))
    mgrs.proto:registerMsg(6015,handler(self.loginData,self.loginData.parseUseProp))
    mgrs.proto:registerMsg(20001,handler(self.loginData,self.loginData.sdkChargeInfo))
end



mgrs.data = nil;
mgrs.singleClass(mgrs,DataMgr,"data");

--endregion
